
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class PortalLayoutDefault
	{
	
		
	
		#region Member Variables

		private int intLayoutID = int.MinValue;
		private int intModuleID = int.MinValue;
		private int intDefaultColumn = int.MinValue;
		private int intDefaultRow = int.MinValue;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "PortalLayoutDefault_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// LayoutID
		/// 
		/// </summary>
		public int LayoutID
		{
			get { return  intLayoutID; }
			set { intLayoutID = value; }
		}

		/// <summary>
		/// ModuleID
		/// 
		/// </summary>
		public int ModuleID
		{
			get { return  intModuleID; }
			set { intModuleID = value; }
		}

		/// <summary>
		/// DefaultColumn
		/// 
		/// </summary>
		public int DefaultColumn
		{
			get { return  intDefaultColumn; }
			set { intDefaultColumn = value; }
		}

		/// <summary>
		/// DefaultRow
		/// 
		/// </summary>
		public int DefaultRow
		{
			get { return  intDefaultRow; }
			set { intDefaultRow = value; }
		}


		#endregion		
		
		
		#region Constructor

		public PortalLayoutDefault()
		{
		}
		private static PortalLayoutDefault _current;
		static PortalLayoutDefault()
		{
			_current = new PortalLayoutDefault();
		}
		public static PortalLayoutDefault Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Portal_LayoutDefault_Select");
				objData.AddParameter("@LayoutID", this.LayoutID);
				objData.AddParameter("@ModuleID", this.ModuleID);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["LayoutID"]))	this.LayoutID = Convert.ToInt32(reader["LayoutID"]);
					if(!this.IsDBNull(reader["ModuleID"]))	this.ModuleID = Convert.ToInt32(reader["ModuleID"]);
					if(!this.IsDBNull(reader["DefaultColumn"]))	this.DefaultColumn = Convert.ToInt32(reader["DefaultColumn"]);
					if(!this.IsDBNull(reader["DefaultRow"]))	this.DefaultRow = Convert.ToInt32(reader["DefaultRow"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : Portal_LayoutDefault
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Portal_LayoutDefault_Insert");
				if(this.LayoutID != int.MinValue) objData.AddParameter("@LayoutID", this.LayoutID);
				if(this.ModuleID != int.MinValue) objData.AddParameter("@ModuleID", this.ModuleID);
				if(this.DefaultColumn != int.MinValue) objData.AddParameter("@DefaultColumn", this.DefaultColumn);
				if(this.DefaultRow != int.MinValue) objData.AddParameter("@DefaultRow", this.DefaultRow);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : Portal_LayoutDefault
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Portal_LayoutDefault_Update");
				if(this.LayoutID != int.MinValue)	objData.AddParameter("@LayoutID", this.LayoutID);
				else objData.AddParameter("@LayoutID", DBNull.Value);
				if(this.ModuleID != int.MinValue)	objData.AddParameter("@ModuleID", this.ModuleID);
				else objData.AddParameter("@ModuleID", DBNull.Value);
				if(this.DefaultColumn != int.MinValue)	objData.AddParameter("@DefaultColumn", this.DefaultColumn);
				else objData.AddParameter("@DefaultColumn", DBNull.Value);
				if(this.DefaultRow != int.MinValue)	objData.AddParameter("@DefaultRow", this.DefaultRow);
				else objData.AddParameter("@DefaultRow", DBNull.Value);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : Portal_LayoutDefault
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Portal_LayoutDefault_Delete");
				objData.AddParameter("@LayoutID", this.LayoutID);
				objData.AddParameter("@ModuleID", this.ModuleID);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : Portal_LayoutDefault
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Portal_LayoutDefault_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	Portal_LayoutDefault objPortal_LayoutDefault = new Portal_LayoutDefault();
			objPortalLayoutDefault.LayoutID = txtLayoutID.Text;
			objPortalLayoutDefault.ModuleID = txtModuleID.Text;
			objPortalLayoutDefault.DefaultColumn = txtDefaultColumn.Text;
			objPortalLayoutDefault.DefaultRow = txtDefaultRow.Text;

		 
		 ******************************************************
		 
		 			txtLayoutID.Text = objPortalLayoutDefault.LayoutID;
			txtModuleID.Text = objPortalLayoutDefault.ModuleID;
			txtDefaultColumn.Text = objPortalLayoutDefault.DefaultColumn;
			txtDefaultRow.Text = objPortalLayoutDefault.DefaultRow;

		 
		*******************************************************/
		
	}
}
